package com.block.api.controller.member;

import com.alibaba.fastjson.JSONObject;
import com.block.common.annotate.NeedToken;
import com.block.common.bean.CommonParam;
import com.block.common.bean.SessionBean;
import com.block.common.exception.ApiException;
import com.block.common.model.dto.LoginReqDTO;
import com.block.common.security.util.ApiUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import com.block.db.entity.ApplicationInfo;
import com.block.db.entity.ChannelBaseInfo;
import com.market.member.service.IMemberBaseInfoService;
import com.market.member.service.IMemberLoginSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/member/auth")
@Validated
public class MemberAuthController {

    @Autowired
    IMemberBaseInfoService memberBaseInfoService;
    @Autowired
    IMemberLoginSessionService memberLoginSessionService;

    /**
     * 上传实名信息
     *
     */
    @NeedToken
    @RequestMapping(value = "/updateAuthInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public String updateAuthInfo(@RequestAttribute(value = "tranData") JSONObject tranData,
                              @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                              @RequestAttribute(value = "uri") String uri,
                              @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                              @RequestAttribute(value = "commonParam") CommonParam commonParam,
                              @RequestAttribute(value = "startDate") Date startdate,
                              @RequestAttribute(value = "ip") String ip) throws ApiException {

        String realname = tranData.getString("realname");
        String idCard = tranData.getString("idcard");

        ResponseVo responseVo = null; //memberAuthInfoService.updateAuthInfo(sessionBean, realname, idCard);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt,  startdate, uri);
    }

    /**
     * 查询用户认证信息
     */
    @NeedToken
    @RequestMapping(value = "/getAuthUserInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public String getAuthUserInfo(@RequestAttribute(value = "tranData") JSONObject tranData,
                              @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                              @RequestAttribute(value = "uri") String uri,
                              @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                              @RequestAttribute(value = "commonParam") CommonParam commonParam,
                              @RequestAttribute(value = "startDate") Date startdate,
                              @RequestAttribute(value = "ip") String ip) throws ApiException {

        ResponseVo responseVo = null;//memberAuthInfoService.getAuthInfo(sessionBean.getUid());
        return ApiUtil.dealReturnJson(responseVo, appEncrypt,  startdate, uri);
    }

    /**
     * 查询人脸认证信息
     * 是否已经认证的状态
     * 以及认证的配置信息
     */
    @NeedToken
    @RequestMapping(value = "/getFaceConfigInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public String getFaceInfo(@RequestAttribute(value = "tranData") JSONObject tranData,
                                 @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                                 @RequestAttribute(value = "uri") String uri,
                                 @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                                 @RequestAttribute(value = "commonParam") CommonParam commonParam,
                                 @RequestAttribute(value = "startDate") Date startdate,
                                 @RequestAttribute(value = "ip") String ip) throws ApiException {

        String reqData = tranData.getString("reqData");

        ResponseVo responseVo = null;//memberAuthInfoService.getAuthConfigInfo(sessionBean.getUid(), reqData);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt,  startdate, uri);
    }

    /**
     * 前端认证完成，请求认证结果
     * 查询认证结果
     */
    @NeedToken
    @RequestMapping(value = "/queryFaceResult", method = {RequestMethod.POST, RequestMethod.GET})
    public String queryAuthResult(@RequestAttribute(value = "tranData") JSONObject tranData,
                                 @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                                 @RequestAttribute(value = "uri") String uri,
                                 @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                                 @RequestAttribute(value = "commonParam") CommonParam commonParam,
                                 @RequestAttribute(value = "startDate") Date startdate,
                                 @RequestAttribute(value = "ip") String ip) throws ApiException {

        String orderNo = tranData.getString("orderNo");

        ResponseVo responseVo = null;//memberAuthInfoService.queryAuthResult(sessionBean.getUid(), orderNo);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt,  startdate, uri);
    }



}
